﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// An event which can be called on the client or on the server - the two execution contexts are not linked (only related in meaning).
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class DualEvent<T> : ClientEvent, IServerEvent<T>
		where T : EventArgs
	{
		/// <summary>
		/// The server-side event handler delegate.
		/// </summary>
		public event EventHandler<T> Server;
		/// <summary>
		/// Gets true if server-side delegate has any handlers attached to it.
		/// </summary>
		[Browsable(false)]
		public bool Active
		{
			get
			{
				return Server != null;
			}
		}
		/// <summary>
		/// Raises the event.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		public void Raise(object sender, T e)
		{
			if (Server != null)
				Server(sender, e);
		}
	}
}
